package com.kfzx.www.emptyviewdemo;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

public class StringAdapter extends RecyclerView.Adapter<StringAdapter.ViewHolder> {
    private Context mContext;
    private List<String> mStringList;


    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView mTextView;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            mTextView = (TextView) itemView.findViewById(R.id.text);
        }
    }

    public StringAdapter(Context context, List<String> stringList) {
        mContext = context;
        mStringList = stringList;
    }

    @NonNull
    @Override
    public StringAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.string_layout, viewGroup, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull StringAdapter.ViewHolder viewHolder, int i) {
        String string = mStringList.get(i);
        viewHolder.mTextView.setText(string);
    }

    @Override
    public int getItemCount() {
        return mStringList.size();
    }
}
